/*$RCSfile: validateMask.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 * Check to see if fields are a valid using a regular expression.
 * Fields are not checked if they are disabled.
 * <p>
 * @param form The form validation is taking place on.
 */
function validateMask(form) {
    var isValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oMasked = eval('new ' + jcv_retrieveFormName(form) + '_mask()');
    for (var x in oMasked) {
        if (!jcv_verifyArrayElement(x, oMasked[x])) {
            continue;
        }
        var field = form[oMasked[x][0]];
        if (!jcv_isFieldPresent(field)) {
            continue;
        }

        if ((field.type == 'hidden' ||
             field.type == 'text' ||
             field.type == 'textarea' ||
             field.type == 'file') &&
            (field.value.length > 0)) {

            if (!jcv_matchPattern(field.value, oMasked[x][2]("mask"))) {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oMasked[x][1];
                isValid = false;
            }
        }
    }

    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return isValid;
}

function jcv_matchPattern(value, mask) {
    return mask.exec(value);
}

/*$RCSfile: validateInteger.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 * Check to see if fields are a valid integer.
 * Fields are not checked if they are disabled.
 * <p>
 * @param form The form validation is taking place on.
 */
function validateInteger(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oInteger = eval('new ' + jcv_retrieveFormName(form) + '_IntegerValidations()');
    for (var x in oInteger) {
        if (!jcv_verifyArrayElement(x, oInteger[x])) {
            continue;
        }
        var field = form[oInteger[x][0]];
        if (!jcv_isFieldPresent(field)) {
            continue;
        }

        if ((field.type == 'hidden' ||
             field.type == 'text' ||
             field.type == 'textarea' ||
             field.type == 'select-one' ||
             field.type == 'radio')) {

            var value = '';
            // get field's value
            if (field.type == "select-one") {
                var si = field.selectedIndex;
                if (si >= 0) {
                    value = field.options[si].value;
                }
            } else {
                value = field.value;
            }

            if (value.length > 0) {

                if (!jcv_isDecimalDigits(value)) {
                    bValid = false;
                    if (i == 0) {
                        focusField = field;
                    }
                    fields[i++] = oInteger[x][1];

                } else {
                    var iValue = parseInt(value, 10);
                    if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
                        if (i == 0) {
                            focusField = field;
                        }
                        fields[i++] = oInteger[x][1];
                        bValid = false;
                    }
                }
            }
        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return bValid;
}

/*$RCSfile: validateShort.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 *  Check to see if fields are a valid short.
 * Fields are not checked if they are disabled.
 * <p>
 * @param form The form validation is taking place on.
 */
function validateShort(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oShort = eval('new ' + jcv_retrieveFormName(form) + '_ShortValidations()');

    for (var x in oShort) {
        if (!jcv_verifyArrayElement(x, oShort[x])) {
            continue;
        }
        var field = form[oShort[x][0]];
        if (!jcv_isFieldPresent(field)) {
            continue;
        }

        if ((field.type == 'hidden' ||
             field.type == 'text' ||
             field.type == 'textarea' ||
             field.type == 'select-one' ||
             field.type == 'radio')) {

            var value = '';
            // get field's value
            if (field.type == "select-one") {
                var si = field.selectedIndex;
                if (si >= 0) {
                    value = field.options[si].value;
                }
            } else {
                value = field.value;
            }

            if (value.length > 0) {
                if (!jcv_isDecimalDigits(value)) {
                    bValid = false;
                    if (i == 0) {
                        focusField = field;
                    }
                    fields[i++] = oShort[x][1];

                } else {

                    var iValue = parseInt(value, 10);
                    if (isNaN(iValue) || !(iValue >= -32768 && iValue <= 32767)) {
                        if (i == 0) {
                            focusField = field;
                        }
                        fields[i++] = oShort[x][1];
                        bValid = false;
                    }
                }
            }
        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return bValid;
}

/*$RCSfile: validateByte.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 * Check to see if fields are a valid byte.
 * Fields are not checked if they are disabled.
 * <p>
 * @param form The form validation is taking place on.
 */
function validateByte(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oByte = eval('new ' + jcv_retrieveFormName(form) + '_ByteValidations()');

    for (var x in oByte) {
        if (!jcv_verifyArrayElement(x, oByte[x])) {
            continue;
        }
        var field = form[oByte[x][0]];
        if (!jcv_isFieldPresent(field)) {
            continue;
        }

        if ((field.type == 'hidden' ||
             field.type == 'text' ||
             field.type == 'textarea' ||
             field.type == 'select-one' ||
             field.type == 'radio')) {

            var value = '';
            // get field's value
            if (field.type == "select-one") {
                var si = field.selectedIndex;
                if (si >= 0) {
                    value = field.options[si].value;
                }
            } else {
                value = field.value;
            }

            if (value.length > 0) {
                if (!jcv_isDecimalDigits(value)) {
                    bValid = false;
                    if (i == 0) {
                        focusField = field;
                    }
                    fields[i++] = oByte[x][1];

                } else {

                    var iValue = parseInt(value, 10);
                    if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) {
                        if (i == 0) {
                            focusField = field;
                        }
                        fields[i++] = oByte[x][1];
                        bValid = false;
                    }
                }
            }

        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return bValid;
}

/*$RCSfile: validateCreditCard.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 * Check to see if fields are a valid creditcard number based on Luhn checksum.
 * Fields are not checked if they are disabled.
 * <p>
 * @param form The form validation is taking place on.
 */
function validateCreditCard(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oCreditCard = eval('new ' + jcv_retrieveFormName(form) + '_creditCard()');

    for (var x in oCreditCard) {
        if (!jcv_verifyArrayElement(x, oCreditCard[x])) {
            continue;
        }
        var field = form[oCreditCard[x][0]];
        if (!jcv_isFieldPresent(field)) {
            continue;
        }
        if ((field.type == 'text' ||
             field.type == 'textarea') &&
            (field.value.length > 0)) {
            if (!jcv_luhnCheck(field.value)) {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oCreditCard[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return bValid;
}

/**
 * Checks whether a given credit card number has a valid Luhn checksum.
 * This allows you to spot most randomly made-up or garbled credit card numbers immediately.
 * Reference: http://www.speech.cs.cmu.edu/~sburke/pub/luhn_lib.html
 */
function jcv_luhnCheck(cardNumber) {
    if (jcv_isLuhnNum(cardNumber)) {
        var no_digit = cardNumber.length;
        var oddoeven = no_digit & 1;
        var sum = 0;
        for (var count = 0; count < no_digit; count++) {
            var digit = parseInt(cardNumber.charAt(count));
            if (!((count & 1) ^ oddoeven)) {
                digit *= 2;
                if (digit > 9) digit -= 9;
            }
            ;
            sum += digit;
        }
        ;
        if (sum == 0) return false;
        if (sum % 10 == 0) return true;
    }
    ;
    return false;
}

function jcv_isLuhnNum(argvalue) {
    argvalue = argvalue.toString();
    if (argvalue.length == 0) {
        return false;
    }
    for (var n = 0; n < argvalue.length; n++) {
        if ((argvalue.substring(n, n + 1) < "0") ||
            (argvalue.substring(n, n + 1) > "9")) {
            return false;
        }
    }
    return true;
}

/*$RCSfile: validateFloat.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 * Check to see if fields are a valid float.
 * Fields are not checked if they are disabled.
 * <p>
 * @param form The form validation is taking place on.
 */
function validateFloat(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oFloat = eval('new ' + jcv_retrieveFormName(form) + '_FloatValidations()');
    for (var x in oFloat) {
        if (!jcv_verifyArrayElement(x, oFloat[x])) {
            continue;
        }
        var field = form[oFloat[x][0]];
        if (!jcv_isFieldPresent(field)) {
            continue;
        }

        if ((field.type == 'hidden' ||
             field.type == 'text' ||
             field.type == 'textarea' ||
             field.type == 'select-one' ||
             field.type == 'radio')) {

            var value = '';
            // get field's value
            if (field.type == "select-one") {
                var si = field.selectedIndex;
                if (si >= 0) {
                    value = field.options[si].value;
                }
            } else {
                value = field.value;
            }

            if (value.length > 0) {
                // remove '.' before checking digits
                var tempArray = value.split('.');
                //Strip off leading '0'
                var zeroIndex = 0;
                var joinedString = tempArray.join('');
                while (joinedString.charAt(zeroIndex) == '0') {
                    zeroIndex++;
                }
                var noZeroString = joinedString.substring(zeroIndex, joinedString.length);

                if (!jcv_isAllDigits(noZeroString) || tempArray.length > 2) {
                    bValid = false;
                    if (i == 0) {
                        focusField = field;
                    }
                    fields[i++] = oFloat[x][1];

                } else {
                    var iValue = parseFloat(value);
                    if (isNaN(iValue)) {
                        if (i == 0) {
                            focusField = field;
                        }
                        fields[i++] = oFloat[x][1];
                        bValid = false;
                    }
                }
            }
        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return bValid;
}

/*$RCSfile: validateIntRange.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 * Check to see if fields is in a valid integer range.
 * Fields are not checked if they are disabled.
 * <p>
 * @param form The form validation is taking place on.
 */
function validateIntRange(form) {
    var isValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oRange = eval('new ' + jcv_retrieveFormName(form) + '_intRange()');
    for (var x in oRange) {
        if (!jcv_verifyArrayElement(x, oRange[x])) {
            continue;
        }
        var field = form[oRange[x][0]];
        if (jcv_isFieldPresent(field)) {
            var value = '';
            if (field.type == 'hidden' ||
                field.type == 'text' || field.type == 'textarea' ||
                field.type == 'radio') {
                value = field.value;
            }
            if (field.type == 'select-one') {
                var si = field.selectedIndex;
                if (si >= 0) {
                    value = field.options[si].value;
                }
            }
            if (value.length > 0) {
                var iMin = parseInt(oRange[x][2]("min"));
                var iMax = parseInt(oRange[x][2]("max"));
                var iValue = parseInt(value, 10);
                if (!(iValue >= iMin && iValue <= iMax)) {
                    if (i == 0) {
                        focusField = field;
                    }
                    fields[i++] = oRange[x][1];
                    isValid = false;
                }
            }
        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return isValid;
}
/*$RCSfile: validateUtilities.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */

/**
 * This is a place holder for common utilities used across the javascript validation
 *
 **/

/**
 * Retreive the name of the form
 * @param form The form validation is taking place on.
 */
function jcv_retrieveFormName(form) {

    // Please refer to Bugs 31534, 35127, 35294, 37315 & 38159
    // for the history of the following code

    var formName;

    if (form.getAttributeNode) {
        if (form.getAttributeNode("id") && form.getAttributeNode("id").value) {
            formName = form.getAttributeNode("id").value;
        } else {
            formName = form.getAttributeNode("name").value;
        }
    } else if (form.getAttribute) {
        if (form.getAttribute("id")) {
            formName = form.getAttribute("id");
        } else {
            formName = form.attributes["name"];
        }
    } else {
        if (form.id) {
            formName = form.id;
        } else {
            formName = form.name;
        }
    }

    return formName;

}

/**
 * Handle error messages.
 * @param messages Array of error messages.
 * @param focusField Field to set focus on.
 */
function jcv_handleErrors(messages, focusField) {
    if (focusField && focusField != null) {
        var doFocus = true;
        if (focusField.disabled || focusField.type == 'hidden') {
            doFocus = false;
        }
        if (doFocus &&
            focusField.style &&
            focusField.style.visibility &&
            focusField.style.visibility == 'hidden') {
            doFocus = false;
        }
        if (doFocus) {
            focusField.focus();
        }
    }
    alert(messages.join('\n'));
}

/**
 * Checks that the array element is a valid
 * Commons Validator element and not one inserted by
 * other JavaScript libraries (for example the
 * prototype library inserts an "extends" into
 * all objects, including Arrays).
 * @param name The element name.
 * @param value The element value.
 */
function jcv_verifyArrayElement(name, element) {
    if (element && element.length && element.length == 3) {
        return true;
    } else {
        return false;
    }
}

/**
 * Checks whether the field is present on the form.
 * @param field The form field.
 */
function jcv_isFieldPresent(field) {
    var fieldPresent = true;
    if (field == null || field == undefined) {
        fieldPresent = false;
    } else {
        if (field.disabled) {
            fieldPresent = false;
        }
    }
    return fieldPresent;
}

/**
 * Check a value only contains valid numeric digits
 * @param argvalue The value to check.
 */
function jcv_isAllDigits(argvalue) {
    argvalue = argvalue.toString();
    var validChars = "0123456789";
    var startFrom = 0;
    if (argvalue.substring(0, 2) == "0x") {
        validChars = "0123456789abcdefABCDEF";
        startFrom = 2;
    } else if (argvalue.charAt(0) == "0") {
        validChars = "01234567";
        startFrom = 1;
    } else if (argvalue.charAt(0) == "-") {
        startFrom = 1;
    }

    for (var n = startFrom; n < argvalue.length; n++) {
        if (validChars.indexOf(argvalue.substring(n, n + 1)) == -1) return false;
    }
    return true;
}

/**
 * Check a value only contains valid decimal digits
 * @param argvalue The value to check.
 */
function jcv_isDecimalDigits(argvalue) {
    argvalue = argvalue.toString();
    var validChars = "0123456789";

    var startFrom = 0;
    if (argvalue.charAt(0) == "-") {
        startFrom = 1;
    }

    for (var n = startFrom; n < argvalue.length; n++) {
        if (validChars.indexOf(argvalue.substring(n, n + 1)) == -1) return false;
    }
    return true;
}

/*$RCSfile: validateDate.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 * Check to see if fields are a valid date.
 * Fields are not checked if they are disabled.
 * <p>
 * @param form The form validation is taking place on.
 */
function validateDate(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oDate = eval('new ' + jcv_retrieveFormName(form) + '_DateValidations()');

    for (var x in oDate) {
        if (!jcv_verifyArrayElement(x, oDate[x])) {
            continue;
        }
        var field = form[oDate[x][0]];
        if (!jcv_isFieldPresent(field)) {
            continue;
        }
        var value = field.value;
        var isStrict = true;
        var datePattern = oDate[x][2]("datePatternStrict");
        // try loose pattern
        if (datePattern == null) {
            datePattern = oDate[x][2]("datePattern");
            isStrict = false;
        }
        if ((field.type == 'hidden' ||
             field.type == 'text' ||
             field.type == 'textarea') &&
            (value.length > 0) && (datePattern.length > 0)) {
            var MONTH = "MM";
            var DAY = "dd";
            var YEAR = "yyyy";
            var orderMonth = datePattern.indexOf(MONTH);
            var orderDay = datePattern.indexOf(DAY);
            var orderYear = datePattern.indexOf(YEAR);
            if ((orderDay < orderYear && orderDay > orderMonth)) {
                var iDelim1 = orderMonth + MONTH.length;
                var iDelim2 = orderDay + DAY.length;
                var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                if (iDelim1 == orderDay && iDelim2 == orderYear) {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{2})(\\d{2})(\\d{4})$")
                            : new RegExp("^(\\d{1,2})(\\d{1,2})(\\d{4})$");
                } else if (iDelim1 == orderDay) {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$")
                            : new RegExp("^(\\d{1,2})(\\d{1,2})[" + delim2 + "](\\d{4})$");
                } else if (iDelim2 == orderYear) {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$")
                            : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})(\\d{4})$");
                } else {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$")
                            : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{4})$");
                }
                var matched = dateRegexp.exec(value);
                if (matched != null) {
                    if (!jcv_isValidDate(matched[2], matched[1], matched[3])) {
                        if (i == 0) {
                            focusField = field;
                        }
                        fields[i++] = oDate[x][1];
                        bValid = false;
                    }
                } else {
                    if (i == 0) {
                        focusField = field;
                    }
                    fields[i++] = oDate[x][1];
                    bValid = false;
                }
            } else if ((orderMonth < orderYear && orderMonth > orderDay)) {
                var iDelim1 = orderDay + DAY.length;
                var iDelim2 = orderMonth + MONTH.length;
                var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                if (iDelim1 == orderMonth && iDelim2 == orderYear) {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{2})(\\d{2})(\\d{4})$")
                            : new RegExp("^(\\d{1,2})(\\d{1,2})(\\d{4})$");
                } else if (iDelim1 == orderMonth) {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$")
                            : new RegExp("^(\\d{1,2})(\\d{1,2})[" + delim2 + "](\\d{4})$");
                } else if (iDelim2 == orderYear) {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$")
                            : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})(\\d{4})$");
                } else {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$")
                            : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{4})$");
                }
                var matched = dateRegexp.exec(value);
                if (matched != null) {
                    if (!jcv_isValidDate(matched[1], matched[2], matched[3])) {
                        if (i == 0) {
                            focusField = field;
                        }
                        fields[i++] = oDate[x][1];
                        bValid = false;
                    }
                } else {
                    if (i == 0) {
                        focusField = field;
                    }
                    fields[i++] = oDate[x][1];
                    bValid = false;
                }
            } else if ((orderMonth > orderYear && orderMonth < orderDay)) {
                var iDelim1 = orderYear + YEAR.length;
                var iDelim2 = orderMonth + MONTH.length;
                var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                if (iDelim1 == orderMonth && iDelim2 == orderDay) {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{4})(\\d{2})(\\d{2})$")
                            : new RegExp("^(\\d{4})(\\d{1,2})(\\d{1,2})$");
                } else if (iDelim1 == orderMonth) {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$")
                            : new RegExp("^(\\d{4})(\\d{1,2})[" + delim2 + "](\\d{1,2})$");
                } else if (iDelim2 == orderDay) {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$")
                            : new RegExp("^(\\d{4})[" + delim1 + "](\\d{1,2})(\\d{1,2})$");
                } else {
                    dateRegexp = isStrict
                            ? new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$")
                            : new RegExp("^(\\d{4})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{1,2})$");
                }
                var matched = dateRegexp.exec(value);
                if (matched != null) {
                    if (!jcv_isValidDate(matched[3], matched[2], matched[1])) {
                        if (i == 0) {
                            focusField = field;
                        }
                        fields[i++] = oDate[x][1];
                        bValid = false;
                    }
                } else {
                    if (i == 0) {
                        focusField = field;
                    }
                    fields[i++] = oDate[x][1];
                    bValid = false;
                }
            } else {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oDate[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return bValid;
}

function jcv_isValidDate(day, month, year) {
    if (month < 1 || month > 12) {
        return false;
    }
    if (day < 1 || day > 31) {
        return false;
    }
    if ((month == 4 || month == 6 || month == 9 || month == 11) &&
        (day == 31)) {
        return false;
    }
    if (month == 2) {
        var leap = (year % 4 == 0 &&
                    (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day == 29 && !leap)) {
            return false;
        }
    }
    return true;
}

/*$RCSfile: validateRequired.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 *  Check to see if fields must contain a value.
 * Fields are not checked if they are disabled.
 * <p>
 * @param form The form validation is taking place on.
 */

function validateRequired(form) {
    var isValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oRequired = eval('new ' + jcv_retrieveFormName(form) + '_required()');

    for (var x in oRequired) {
        if (!jcv_verifyArrayElement(x, oRequired[x])) {
            continue;
        }
        var field = form[oRequired[x][0]];

        if (!jcv_isFieldPresent(field)) {
            fields[i++] = oRequired[x][1];
            isValid = false;
        } else if ((field.type == 'hidden' ||
                    field.type == 'text' ||
                    field.type == 'textarea' ||
                    field.type == 'file' ||
                    field.type == 'radio' ||
                    field.type == 'checkbox' ||
                    field.type == 'select-one' ||
                    field.type == 'password')) {

            var value = '';
            // get field's value
            if (field.type == "select-one") {
                var si = field.selectedIndex;
                if (si >= 0) {
                    value = field.options[si].value;
                }
            } else if (field.type == 'radio' || field.type == 'checkbox') {
                if (field.checked) {
                    value = field.value;
                }
            } else {
                value = field.value;
            }

            if (trim(value).length == 0) {

                if ((i == 0) && (field.type != 'hidden')) {
                    focusField = field;
                }
                fields[i++] = oRequired[x][1];
                isValid = false;
            }
        } else if (field.type == "select-multiple") {
            var numOptions = field.options.length;
            lastSelected = -1;
            for (loop = numOptions - 1; loop >= 0; loop--) {
                if (field.options[loop].selected) {
                    lastSelected = loop;
                    value = field.options[loop].value;
                    break;
                }
            }
            if (lastSelected < 0 || trim(value).length == 0) {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oRequired[x][1];
                isValid = false;
            }
        } else if ((field.length > 0) && (field[0].type == 'radio' || field[0].type == 'checkbox')) {
            isChecked = -1;
            for (loop = 0; loop < field.length; loop++) {
                if (field[loop].checked) {
                    isChecked = loop;
                    break;
                    // only one needs to be checked
                }
            }
            if (isChecked < 0) {
                if (i == 0) {
                    focusField = field[0];
                }
                fields[i++] = oRequired[x][1];
                isValid = false;
            }
        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return isValid;
}

// Trim whitespace from left and right sides of s.
function trim(s) {
    return s.replace(/^\s*/, "").replace(/\s*$/, "");
}

/*$RCSfile: validateFloatRange.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 * Check to see if fields are in a valid float range.
 * Fields are not checked if they are disabled.
 * <p>
 * @param form The form validation is taking place on.
 */
function validateFloatRange(form) {
    var isValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oRange = eval('new ' + jcv_retrieveFormName(form) + '_floatRange()');
    for (var x in oRange) {
        if (!jcv_verifyArrayElement(x, oRange[x])) {
            continue;
        }
        var field = form[oRange[x][0]];
        if (!jcv_isFieldPresent(field)) {
            continue;
        }

        if ((field.type == 'hidden' ||
             field.type == 'text' || field.type == 'textarea') &&
            (field.value.length > 0)) {

            var fMin = parseFloat(oRange[x][2]("min"));
            var fMax = parseFloat(oRange[x][2]("max"));
            var fValue = parseFloat(field.value);
            if (!(fValue >= fMin && fValue <= fMax)) {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oRange[x][1];
                isValid = false;
            }
        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return isValid;
}

/*$RCSfile: validateMinLength.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 * A field is considered valid if greater than the specified minimum.
 * Fields are not checked if they are disabled.
 * <p>
 * <strong>Caution:</strong> Using <code>validateMinLength</code> on a password field in a
 *  login page gives unnecessary information away to hackers. While it only slightly
 *  weakens security, we suggest using it only when modifying a password.</p>
 * @param form The form validation is taking place on.
 */
function validateMinLength(form) {
    var isValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oMinLength = eval('new ' + jcv_retrieveFormName(form) + '_minlength()');

    for (var x in oMinLength) {
        if (!jcv_verifyArrayElement(x, oMinLength[x])) {
            continue;
        }
        var field = form[oMinLength[x][0]];
        if (!jcv_isFieldPresent(field)) {
            continue;
        }

        if ((field.type == 'hidden' ||
             field.type == 'text' ||
             field.type == 'password' ||
             field.type == 'textarea')) {

            /* Adjust length for carriage returns - see Bug 37962 */
            var lineEndLength = oMinLength[x][2]("lineEndLength");
            var adjustAmount = 0;
            if (lineEndLength) {
                var rCount = 0;
                var nCount = 0;
                var crPos = 0;
                while (crPos < field.value.length) {
                    var currChar = field.value.charAt(crPos);
                    if (currChar == '\r') {
                        rCount++;
                    }
                    if (currChar == '\n') {
                        nCount++;
                    }
                    crPos++;
                }
                var endLength = parseInt(lineEndLength);
                adjustAmount = (nCount * endLength) - (rCount + nCount);
            }

            var iMin = parseInt(oMinLength[x][2]("minlength"));
            if ((trim(field.value).length > 0) && ((field.value.length + adjustAmount) < iMin)) {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oMinLength[x][1];
                isValid = false;
            }
        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return isValid;
}

/*$RCSfile: validateMaxLength.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 * A field is considered valid if less than the specified maximum.
 * Fields are not checked if they are disabled.
 * <p>
 * <strong>Caution:</strong> Using <code>validateMaxLength</code> on a password field in a
 *  login page gives unnecessary information away to hackers. While it only slightly
 *  weakens security, we suggest using it only when modifying a password.</p>
 * @param form The form validation is taking place on.
 */
function validateMaxLength(form) {
    var isValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oMaxLength = eval('new ' + jcv_retrieveFormName(form) + '_maxlength()');
    for (var x in oMaxLength) {
        if (!jcv_verifyArrayElement(x, oMaxLength[x])) {
            continue;
        }
        var field = form[oMaxLength[x][0]];
        if (!jcv_isFieldPresent(field)) {
            continue;
        }

        if ((field.type == 'hidden' ||
             field.type == 'text' ||
             field.type == 'password' ||
             field.type == 'textarea')) {

            /* Adjust length for carriage returns - see Bug 37962 */
            var lineEndLength = oMaxLength[x][2]("lineEndLength");
            var adjustAmount = 0;
            if (lineEndLength) {
                var rCount = 0;
                var nCount = 0;
                var crPos = 0;
                while (crPos < field.value.length) {
                    var currChar = field.value.charAt(crPos);
                    if (currChar == '\r') {
                        rCount++;
                    }
                    if (currChar == '\n') {
                        nCount++;
                    }
                    crPos++;
                }
                var endLength = parseInt(lineEndLength);
                adjustAmount = (nCount * endLength) - (rCount + nCount);
            }

            var iMax = parseInt(oMaxLength[x][2]("maxlength"));
            if ((field.value.length + adjustAmount) > iMax) {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oMaxLength[x][1];
                isValid = false;
            }
        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return isValid;
}

/*$RCSfile: validateEmail.js,v $ $Rev: 376673 $ $Date: 2006-02-10 13:42:31 +0000 (Fri, 10 Feb 2006) $ */
/**
 * Check to see if fields are a valid email address.
 * Fields are not checked if they are disabled.
 * <p>
 * @param form The form validation is taking place on.
 */
function validateEmail(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();

    var oEmail = eval('new ' + jcv_retrieveFormName(form) + '_email()');

    for (var x in oEmail) {
        if (!jcv_verifyArrayElement(x, oEmail[x])) {
            continue;
        }
        var field = form[oEmail[x][0]];
        if (!jcv_isFieldPresent(field)) {
            continue;
        }
        if ((field.type == 'hidden' ||
             field.type == 'text' ||
             field.type == 'textarea') &&
            (field.value.length > 0)) {
            if (!jcv_checkEmail(field.value)) {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oEmail[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        jcv_handleErrors(fields, focusField);
    }
    return bValid;
}

/**
 * Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com),
 * http://javascript.internet.com
 */
function jcv_checkEmail(emailStr) {
    if (emailStr.length == 0) {
        return true;
    }
    // TLD checking turned off by default
    var checkTLD = 0;
    var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    var emailPat = /^(.+)@(.+)$/;
    var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
    var validChars = "\[^\\s" + specialChars + "\]";
    var quotedUser = "(\"[^\"]*\")";
    var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var atom = validChars + '+';
    var word = "(" + atom + "|" + quotedUser + ")";
    var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat = new RegExp("^" + atom + "(\\." + atom + ")*$");
    var matchArray = emailStr.match(emailPat);
    if (matchArray == null) {
        return false;
    }
    var user = matchArray[1];
    var domain = matchArray[2];
    for (i = 0; i < user.length; i++) {
        if (user.charCodeAt(i) > 127) {
            return false;
        }
    }
    for (i = 0; i < domain.length; i++) {
        if (domain.charCodeAt(i) > 127) {
            return false;
        }
    }
    if (user.match(userPat) == null) {
        return false;
    }
    var IPArray = domain.match(ipDomainPat);
    if (IPArray != null) {
        for (var i = 1; i <= 4; i++) {
            if (IPArray[i] > 255) {
                return false;
            }
        }
        return true;
    }
    var atomPat = new RegExp("^" + atom + "$");
    var domArr = domain.split(".");
    var len = domArr.length;
    for (i = 0; i < len; i++) {
        if (domArr[i].search(atomPat) == -1) {
            return false;
        }
    }
    if (checkTLD && domArr[domArr.length - 1].length != 2 &&
        domArr[domArr.length - 1].search(knownDomsPat) == -1) {
        return false;
    }
    if (len < 2) {
        return false;
    }
    return true;
}


function vaildateEqual(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();


    //oEqual = new equal();
    var formName = form.getAttributeNode("name");
    oEqual = eval('new ' + formName.value + '_equal()');

    for (x in oEqual) {
        var field = form[oEqual[x][0]];
        if (field.type == 'text' ||
            field.type == 'textarea') {
            if (field.value == '') {
                field.value = 0;
            }
            var yvalue = parseFloat(field.value);
            var ivalue = iequal(oEqual[x][2]("equal"), form);
            var itype = oEqual[x][2]("type");
            var re = yvalue - ivalue;
            if (typeof oEqual[x][2]("Difference_maxvalue") == "undefined") {
                var Difference_maxvalue = "0.5";
            } else
            {
                var Difference_maxvalue = oEqual[x][2]("Difference_maxvalue") ;
            }
            if (typeof oEqual[x][2]("Difference_minvalue") == "undefined") {
                var Difference_minvalue = "-0.5";
            } else
            {
                var Difference_minvalue = oEqual[x][2]("Difference_minvalue") ;
            }
            if (parseFloat(Difference_maxvalue) == 0) {
                Difference_maxvalue = "0.5"
            }
            ;
            if (parseFloat(Difference_minvalue) == 0) {
                Difference_minvalue = "-0.5"
            }
            ;
            if ((itype == '=' && (re > parseFloat(Difference_maxvalue) || re < parseFloat(Difference_minvalue))) ||
                (itype == '#1#' && re < parseFloat(Difference_minvalue)) || (itype == '#2#' && re < parseFloat(Difference_minvalue))
                    || (itype == '#3#' && re > parseFloat(Difference_maxvalue)) || (itype == '#4#' && re > parseFloat(Difference_maxvalue))) {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oEqual[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function CalculateEqual2(form) {
    //oEqual = new equal();
    var formName = form.getAttributeNode("name");
    oEqual = eval('new ' + formName.value + '_equal()');
    //oEqual_if = new equal_if();
    try{
        oEqual_if = eval('new ' + formName.value + '_equal_if()');
    }catch(e){
        //svar oEqual_if;
    }
    var i = 1;
    var break_bz = true;
    while (true) {
        for (x in oEqual) {
            //alert(parseInt(oEqual[x][2]("No_Step")));
            if (parseInt(oEqual[x][2]("No_Step")) == i) {
                break_bz = false;
                if (oEqual[x][2]("type") == "=") {
                    if (!isNaN(parseFloat(iequal(oEqual[x][2]("equal"), form)))) {
                        var ss = iequal(oEqual[x][2]("equal"), form)  ;
                    }
                    else     var ss = 0;
                    if (parseFloat(oEqual[x][2]("Difference_minvalue")) == 0) {
                        form[oEqual[x][0]].value = formatnumber(ss);
                    } else {
                        if (form[oEqual[x][0]].value == "") {
                            form[oEqual[x][0]].value = 0;
                        }
                        if ((parseFloat(form[oEqual[x][0]].value) - formatnumber(ss)) > parseFloat(oEqual[x][2]("Difference_maxvalue")) || (parseFloat(form[oEqual[x][0]].value) - formatnumber(ss)) < parseFloat(oEqual[x][2]("Difference_minvalue"))) {
                            form[oEqual[x][0]].value = formatnumber(ss);
                        }
                    }
                }
                break;
            }
        }
        if (break_bz == true) {
            try{
            for (y in oEqual_if) {
                if (parseInt(oEqual_if[y][2]("No_Step")) == i) {
                    break_bz = false;
                    if (oEqual_if[y][2]("equal_type") == "=") {
                        var ivalue_0 = iequal(oEqual_if[y][2]("if_equal_0"), form);
                        var ivalue_1 = iequal(oEqual_if[y][2]("if_equal_1"), form);
                        if (getresult(ivalue_0, oEqual_if[y][2]("if_type"), ivalue_1)) {
                            var ivalue = iequal(oEqual_if[y][2]("equal_true"), form);
                        } else {
                            var ivalue = iequal(oEqual_if[y][2]("equal_false"), form);
                        }
                        if (!isNaN(ivalue)) {
                            var ss = ivalue  ;
                        }
                        else     var ss = 0;

                        if (parseFloat(oEqual_if[y][2]("Difference_minvalue")) == 0) {
                            form[oEqual_if[y][0]].value = formatnumber(ss);
                        } else {
                            if (form[oEqual_if[y][0]].value == "") {
                                form[oEqual_if[y][0]].value = 0;
                            }
                            if ((parseFloat(form[oEqual_if[y][0]].value) - formatnumber(ss)) > parseFloat(oEqual_if[y][2]("Difference_mayvalue")) || (parseFloat(form[oEqual_if[y][0]].value) - formatnumber(ss)) < parseFloat(oEqual_if[y][2]("Difference_minvalue"))) {
                                form[oEqual_if[y][0]].value = formatnumber(ss);
                            }
                        }
                        break;
                    }
                }
            } }catch(e){}
        }
        if (break_bz == true) {
            break;
        }
        break_bz = true;
        i = i + 1;
    }
}

function CalculateEqual3000(form) {
    //oEqual = new equal();
    var formName = form.getAttributeNode("name");
    oEqual = eval('new ' + formName.value + '_equal()');
    //oEqual_if = new equal_if();
    try{
        oEqual_if = eval('new ' + formName.value + '_equal_if()');
    }catch(e){
        //svar oEqual_if;
    }
    var i = 1;
    var break_bz = true;
    while (i<3000) {
        for (x in oEqual) {
            //alert(parseInt(oEqual[x][2]("No_Step")));
            if (parseInt(oEqual[x][2]("No_Step")) == i) {
                break_bz = false;
                if (oEqual[x][2]("type") == "=") {
                    if (!isNaN(parseFloat(iequal(oEqual[x][2]("equal"), form)))) {
                        var ss = iequal(oEqual[x][2]("equal"), form)  ;
                    }
                    else     var ss = 0;
                    if (parseFloat(oEqual[x][2]("Difference_minvalue")) == 0) {
                        form[oEqual[x][0]].value = formatnumber(ss);
                    } else {
                        if (form[oEqual[x][0]].value == "") {
                            form[oEqual[x][0]].value = 0;
                        }
                        if ((parseFloat(form[oEqual[x][0]].value) - formatnumber(ss)) > parseFloat(oEqual[x][2]("Difference_maxvalue")) || (parseFloat(form[oEqual[x][0]].value) - formatnumber(ss)) < parseFloat(oEqual[x][2]("Difference_minvalue"))) {
                            form[oEqual[x][0]].value = formatnumber(ss);
                        }
                    }
                }
                break;
            }
        }
        if (break_bz == true) {
            try{
            for (y in oEqual_if) {
                if (parseInt(oEqual_if[y][2]("No_Step")) == i) {
                    break_bz = false;
                    if (oEqual_if[y][2]("equal_type") == "=") {
                        var ivalue_0 = iequal(oEqual_if[y][2]("if_equal_0"), form);
                        var ivalue_1 = iequal(oEqual_if[y][2]("if_equal_1"), form);
                        if (getresult(ivalue_0, oEqual_if[y][2]("if_type"), ivalue_1)) {
                            var ivalue = iequal(oEqual_if[y][2]("equal_true"), form);
                        } else {
                            var ivalue = iequal(oEqual_if[y][2]("equal_false"), form);
                        }
                        if (!isNaN(ivalue)) {
                            var ss = ivalue  ;
                        }
                        else     var ss = 0;

                        if (parseFloat(oEqual_if[y][2]("Difference_minvalue")) == 0) {
                            form[oEqual_if[y][0]].value = formatnumber(ss);
                        } else {
                            if (form[oEqual_if[y][0]].value == "") {
                                form[oEqual_if[y][0]].value = 0;
                            }
                            if ((parseFloat(form[oEqual_if[y][0]].value) - formatnumber(ss)) > parseFloat(oEqual_if[y][2]("Difference_mayvalue")) || (parseFloat(form[oEqual_if[y][0]].value) - formatnumber(ss)) < parseFloat(oEqual_if[y][2]("Difference_minvalue"))) {
                                form[oEqual_if[y][0]].value = formatnumber(ss);
                            }
                        }
                        break;
                    }
                }
            } }catch(e){}
        }
        if (break_bz == true) {
           // break;
        }
        break_bz = true;
        i = i + 1;
    }
}

function CalculateEqual3(Step_No, form) {
    var i = parseInt(Step_No);
    var break_bz = true;
    if (typeof equal != "undefined") {
        var formName = form.getAttributeNode("name");
        oEqual = eval('new ' + formName.value + '_equal()');

        //oEqual = new equal();
        for (x in oEqual) {
            if (parseInt(oEqual[x][2]("No_Step")) == i) {
                break_bz = false;
                if (oEqual[x][2]("type") == "=") {
                    if (!isNaN(parseFloat(iequal(oEqual[x][2]("equal"), form)))) {
                        var ss = iequal(oEqual[x][2]("equal"), form)  ;
                    }
                    else     var ss = 0;
                    if (parseFloat(oEqual[x][2]("Difference_minvalue")) == 0) {
                        form[oEqual[x][0]].value = formatnumber(ss);
                    } else {
                        if (form[oEqual[x][0]].value == "") {
                            form[oEqual[x][0]].value = 0;
                        }
                        if ((parseFloat(form[oEqual[x][0]].value) - formatnumber(ss)) > parseFloat(oEqual[x][2]("Difference_maxvalue")) || (parseFloat(form[oEqual[x][0]].value) - formatnumber(ss)) < parseFloat(oEqual[x][2]("Difference_minvalue"))) {
                            form[oEqual[x][0]].value = formatnumber(ss);
                        }
                    }
                }
                break;
            }
        }
    }
    if (typeof equal_if != "undefined") {
        //oEqual_if = new equal_if();
        oEqual_if = eval('new ' + formName.value + '_equal_if()');
        if (break_bz == true) {
            for (y in oEqual_if) {
                if (parseInt(oEqual_if[y][2]("No_Step")) == i) {
                    break_bz = false;
                    if (oEqual_if[y][2]("equal_type") == "=") {
                        var ivalue_0 = iequal(oEqual_if[y][2]("if_equal_0"), form);
                        var ivalue_1 = iequal(oEqual_if[y][2]("if_equal_1"), form);
                        if (getresult(ivalue_0, oEqual_if[y][2]("if_type"), ivalue_1)) {
                            var ivalue = iequal(oEqual_if[y][2]("equal_true"), form);
                        } else {
                            var ivalue = iequal(oEqual_if[y][2]("equal_false"), form);
                        }
                        if (!isNaN(ivalue)) {
                            var ss = ivalue  ;
                        }
                        else     var ss = 0;

                        if (parseFloat(oEqual_if[y][2]("Difference_minvalue")) == 0) {
                            form[oEqual_if[y][0]].value = formatnumber(ss);
                        } else {
                            if (form[oEqual_if[y][0]].value == "") {
                                form[oEqual_if[y][0]].value = 0;
                            }
                            if ((parseFloat(form[oEqual_if[y][0]].value) - formatnumber(ss)) > parseFloat(oEqual_if[y][2]("Difference_mayvalue")) || (parseFloat(form[oEqual_if[y][0]].value) - formatnumber(ss)) < parseFloat(oEqual_if[y][2]("Difference_minvalue"))) {
                                form[oEqual_if[y][0]].value = formatnumber(ss);
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
}


function CalculateEqual(field, form) {
    //oEqual = new equal();
    var formName = form.getAttributeNode("name");
    oEqual = eval('new ' + formName.value + '_equal()');
    for (x in oEqual) {
        if (oEqual[x][2]("type") == "=") {
            if ((oEqual[x][2]("equal").indexOf(field.name) != -1  ) || (field.name == form[oEqual[x][0]].name )) {
                if (!isNaN(parseFloat(iequal(oEqual[x][2]("equal"), form)))) {
                    //alert(oEqual[x][2]("equal"));
                    var ss = iequal(oEqual[x][2]("equal"), form)  ;
                }
                else     var ss = 0;
                //alert(oEqual[x][0]);
                //alert(form[oEqual[x][0]]);
                //alert(ss);
                if (parseFloat(oEqual[x][2]("Difference_minvalue")) == 0) {
                    //alert('a');
                    form[oEqual[x][0]].value = formatnumber(ss);
                } else {
                    if (form[oEqual[x][0]].value == "") {
                        //alert('b');
                        form[oEqual[x][0]].value = 0;
                    }
                    if ((parseFloat(form[oEqual[x][0]].value) - formatnumber(ss)) > parseFloat(oEqual[x][2]("Difference_maxvalue")) || (parseFloat(form[oEqual[x][0]].value) - formatnumber(ss)) < parseFloat(oEqual[x][2]("Difference_minvalue"))) {
                        //alert('c');
                        form[oEqual[x][0]].value = formatnumber(ss);
                    }
                }

                //alert(form[oEqual[x][0]].value);
            }
        }
    }
}

function valifloat(field) {
    if (isNaN(field.value)) ok = "no"; else ok = "yes";
    if (ok == "yes") {
        if (parseFloat(field.value)) {
            ok = "yes"
        }
        else ok = "no";
    }
    if (ok == "yes") {
        while ((field.value.substring(0, 1) == 0) && (field.value.length > 1) && (field.value.substring(1, 2) != '.')) {
            field.value = field.value.substring(1, field.value.length)
        }
    }
    if (ok == "no") {
        if (field.value == 0) {
            ok = "yes";
            field.value = 0;
        }
    }
    if (ok == "no") {
        alert("提示信息:非法数字！");
        field.value = 0;
        field.focus();
        return false;
    }
    else return true;
}

function valiint(field) {
    var valid = "0123456789"
    var ok = "yes";
    var temp;
    for (var i = 0; i < field.value.length; i++) {
        temp = "" + field.value.substring(i, i + 1);
        if (valid.indexOf(temp) == "-1") ok = "no";
    }
    if (ok == "yes") {
        while ((field.value.substring(0, 1) == 0) && (field.value.length > 1)) {
            field.value = field.value.substring(1, field.value.length)
        }
    }
    if (ok == "no") {
        alert("提示信息:只能入正整数或零！");
        field.value = 0;
        field.focus();
        return false;
    }
    //wzz 20120418 修改增值税附表一发票份数最大额为：2000000
    else
        if (field.value >2000000) {
            alert("提示信息:不能大于2000000");
            field.focus();
            return false;
        }
        else
            return true;
}


function valifloatformat(field) {debugger;
    if (isNaN(field.value)) ok = "no"; else ok = "yes";
    if (ok == "yes") {
        if (parseFloat(field.value)) {
            ok = "yes";
        }
        else ok = "no";
    }
    if (ok == "yes") {
        while ((field.value.substring(0, 1) == 0) && (field.value.length > 1) && (field.value.substring(1, 2) != '.')) {
            field.value = field.value.substring(1, field.value.length);
        }
    }
    if (ok == "no") {
        if (field.value == 0) {
            ok = "yes";
            field.value = 0;
        }
    }
    if (ok == "no") {
        alert("提示信息:非法数字！");
        field.value = 0;
        field.focus();
        return false;
    }
    else
    {
        field.value = formatnumber(field.value);
        return true;
    }
}

function valifloatformat_4(field) {
    if (isNaN(field.value)) ok = "no"; else ok = "yes";
    if (ok == "yes") {
        if (parseFloat(field.value)) {
            ok = "yes"
        }
        else ok = "no";
    }
    if (ok == "yes") {
        while ((field.value.substring(0, 1) == 0) && (field.value.length > 1) && (field.value.substring(1, 2) != '.')) {
            field.value = field.value.substring(1, field.value.length)
        }
    }
    if (ok == "no") {
        if (field.value == 0) {
            ok = "yes";
            field.value = 0;
        }
    }
    if (ok == "no") {
        alert("提示信息:非法数字！");
        field.value = 0;
        field.focus();
        return false;
    }
    else
    {
        field.value = formatnumber_4(field.value);
        return true;
    }
}

function valifloatformat_6(field) {
    if (isNaN(field.value)) ok = "no"; else ok = "yes";
    if (ok == "yes") {
        if (parseFloat(field.value)) {
            ok = "yes"
        }
        else ok = "no";
    }
    if (ok == "yes") {
        while ((field.value.substring(0, 1) == 0) && (field.value.length > 1) && (field.value.substring(1, 2) != '.')) {
            field.value = field.value.substring(1, field.value.length)
        }
    }
    if (ok == "no") {
        if (field.value == 0) {
            ok = "yes";
            field.value = 0;
        }
    }
    if (ok == "no") {
        alert("提示信息:非法数字！");
        field.value = 0;
        field.focus();
        return false;
    }
    else
    {
        field.value = formatnumber_6(field.value);
        return true;
    }
}

function valifloatformat_0(field) {
    if (isNaN(field.value)) ok = "no"; else ok = "yes";
    if (ok == "yes") {
        if (parseFloat(field.value)) {
            ok = "yes"
        }
        else ok = "no";
    }
    if (ok == "yes") {
        while ((field.value.substring(0, 1) == 0) && (field.value.length > 1) && (field.value.substring(1, 2) != '.')) {
            field.value = field.value.substring(1, field.value.length)
        }
    }
    if (ok == "no") {
        if (field.value == 0) {
            ok = "yes";
            field.value = 0;
        }
    }
    if (ok == "no") {
        alert("提示信息:非法数字！");
        field.value = 0;
        field.focus();
        return false;
    }
    else
    {
        var ls_value = formatnumber(field.value)
        if (ls_value < 0) {
            alert("提示信息:不得小于零！");
            field.value = 0;
            field.focus();
            return false;
        }
        else
        {
            field.value = ls_value;
            return true;
        }
    }
}

//四舍五人保留两位小数
function formatnumber(n)
{
    var num,intPart,dotPart,allPart,dotPos,destNum;
    //小数点位置
    dotPos = String(n).indexOf(".");
    //整数，不处理
    if (dotPos == -1)
        destNum = n;
    //有小数
    else
    {
        //整数部分(含小数点)
        intPart = String(n).substring(0, dotPos + 1);
        //小数部分
        dotPart = String(n).substring(dotPos + 1);
        //小数位数小于2，不处理
        if (dotPart.length <= 2)
            destNum = n;
        //小数位数大于等于3
        else
        {

            var tmp0,tmp1,tmp2,tmp3;
            //小数点后第一位数
            tmp0 = String(dotPart).charAt(0);
            //小数点后第二位数
            tmp1 = String(dotPart).charAt(1);
            //小数点后第三位数
            tmp2 = String(dotPart).charAt(2);
            //小数点后第三位数为5
            if (tmp2 == 5)
            {
                //小数点后第二位数为奇数1,3,5,7，round函数自动进位
                if (tmp1 == 5) {
                    //alert('n:'+n);
                    //alert(Math.round(n*100)) ;
                    tmp1 = Number(tmp1) + Number(1);
                    destNum = intPart + tmp0 + tmp1;
                    //destNum=Math.round(n*100)/100+0.01;
                    //alert('destNum:'+destNum) ;
                }
                //小数点后第二位数为偶数0,2,4,6,8，用以下方法进位
                else
                    if (tmp1 == 9)
                    {
                        //小数点后第二位数加1
                        if (tmp0 == 9) {
                            //整数与小数合并
                            destNum = Number(intPart) + Number(1);
                        }
                        else {
                            tmp0 = Number(tmp0) + Number(1);
                            //整数与小数合并
                            destNum = intPart + tmp0;
                        }
                    }
                    else
                    {
                        //小数点后第二位数加1
                        tmp1 = Number(tmp1) + Number(1);
                        //整数与小数合并
                        destNum = intPart + tmp0 + tmp1;
                    }
            }
            //小数点后第三位数不为5，round函数自动进位
            else
                destNum = Math.round(n * 100) / 100;
        }
    }
    return(destNum);
}

//四舍五人保留四位小数
<!--function formatnumber(n)-->
<!--{-->
<!--	destNum=Math.round(n*100)/100;-->
<!--	return(destNum);-->
<!--}-->

//四舍五人保留四位小数
function formatnumber_4(n)
{
    destNum = Math.round(n * 10000) / 10000;
    return(destNum);
}
//四舍五人保留六位小数
function formatnumber_6(n)
{
    destNum = Math.round(n * 1000000) / 1000000;
    return(destNum);
}

function iequal(qual, form) {
    split0 = qual.split('#~#');
    var valueArray = new Array(split0.length + 1);
    var value = 0;
    var _fieldName;
    for (t = 0; t <= split0.length; t++) {
        split = split0[t].split(',');
        if (split[0].indexOf("#abs#")>-1){
           _fieldName= split[0].substr(5);
        }else{
            _fieldName= split[0];
        }
        if (form[_fieldName].value != "") {
            if (split[0].indexOf("#abs#")>-1){
                valueArray[t] = Math.abs(parseFloat(form[_fieldName].value));
            }else{
                valueArray[t] = parseFloat(form[_fieldName].value);                
            }
        }
        else {
            valueArray[t] = 0;
        }
        for (i = 0; i < split.length - 1; i++) {
            l = i + 1;
            if (split[l].indexOf("#abs#")>-1){
              _fieldName= split[l].substr(5);
            }else{
              _fieldName= split[l];
            }
            if (split[i] == '+') {
                if (form[_fieldName].value != "")
                {
                    if (split[l].indexOf("#abs#")>-1){
                       valueArray[t] = formatnumber(parseFloat(valueArray[t]) + Math.abs(parseFloat(form[_fieldName].value)));
                    }else{
                       valueArray[t] = formatnumber(parseFloat(valueArray[t]) + parseFloat(form[_fieldName].value));
                    }
                 }
              }
            if (split[i] == '-') {
                if (form[split[l]].value != "") {
                    if (split[l].indexOf("#abs#")>-1){
                        valueArray[t] = formatnumber(parseFloat(valueArray[t]) - Math.abs(parseFloat(form[_fieldName].value)));
                    }else{
                        valueArray[t] = formatnumber(parseFloat(valueArray[t]) - parseFloat(form[_fieldName].value));
                    }
                }
            }
            if (split[i] == '*') {
                if (form[_fieldName].value != "") {
                    //alert(valueArray[t]);
                    //alert(form[split[l]].value) ;
                    //alert('='+valueArray[t]*parseFloat(form[split[l]].value));
                    //valueArray[t]=formatnumber(formatnumber(parseFloat(valueArray[t])*parseFloat(form[split[l]].value)*100)/100);
                    if (split[l].indexOf("#abs#")>-1){
                        var s1 = formatnumber(formatnumber(parseFloat(valueArray[t]) * Math.abs(parseFloat(form[_fieldName].value)) * 100) / 100);
                        var s2 = Math.round(parseFloat(valueArray[t]) * Math.abs(parseFloat(form[_fieldName].value)) * 100) / 100;
                        //alert(s1);
                        //alert(s2);
                        if (s1 > s2)
                        {
                            valueArray[t] = formatnumber(formatnumber(parseFloat(valueArray[t]) * Math.abs(parseFloat(form[_fieldName].value)) * 100) / 100);
                        } else {
                            valueArray[t] = Math.round(parseFloat(valueArray[t]) * Math.abs(parseFloat(form[_fieldName].value)) * 100) / 100;
                        }
                    }else{
                        var s1 = formatnumber(formatnumber(parseFloat(valueArray[t]) * parseFloat(form[_fieldName].value) * 100) / 100);
                        var s2 = Math.round(parseFloat(valueArray[t]) * parseFloat(form[_fieldName].value) * 100) / 100;
                        //alert(s1);
                        //alert(s2);
                        if (s1 > s2)
                        {
                            valueArray[t] = formatnumber(formatnumber(parseFloat(valueArray[t]) * parseFloat(form[_fieldName].value) * 100) / 100);
                        } else {
                            valueArray[t] = Math.round(parseFloat(valueArray[t]) * parseFloat(form[_fieldName].value) * 100) / 100;
                        }
                    }

                    //valueArray[t]=formatnumber(parseFloat(valueArray[t])*parseFloat(form[split[l]].value));
                    //alert(valueArray[t]);
                }
            }
            if (split[i] == '/') {
                if (form[_fieldName].value != "") {
                    if (split[l].indexOf("#abs#")>-1){
                        valueArray[t] = formatnumber(parseFloat(valueArray[t]) / Math.abs(parseFloat(form[_fieldName].value)));
                    }else{
                        valueArray[t] = formatnumber(parseFloat(valueArray[t]) / parseFloat(form[_fieldName].value));
                    }
                }
            }
            if (split[i] == '/@') {
                if (form[_fieldName].value != "") {
                    if (split[l].indexOf("#abs#")>-1){
                        valueArray[t] = formatnumber(Math.abs(parseFloat(form[_fieldName].value)) / parseFloat(valueArray[t]));
                    }else{
                        valueArray[t] = formatnumber(parseFloat(form[_fieldName].value) / parseFloat(valueArray[t]));
                    }
                }
            }
            valueArray[t + 1] = split0[t + 1];
        }
        t = t + 1;
    }
    t = 0;
    value = valueArray[t];
    for (t = 0; t <= valueArray.length; t++) {
        s = t + 1;
        if (valueArray[s] == '+') {
            value = formatnumber(value + valueArray[s + 1])
        }
        if (valueArray[s] == '-') {
            value = formatnumber(value - valueArray[s + 1])
        }
        if (valueArray[s] == '*') {
            value = formatnumber(value * valueArray[s + 1])
        }
        if (valueArray[s] == '/') {
            value = formatnumber(value / valueArray[s + 1])
        }
        if (valueArray[s] == '/@') {
            value = formatnumber(valueArray[s + 1] / value)
        }
        t = t + 1;
    }
    return value;
}
function vaildateEqual_0(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oEqual = eval('new ' + formName.value + '_equal_0()');
    //oEqual = new equal_0();
    for (x in oEqual) {
        var field = form[oEqual[x][0]];
        if (field.type == 'text' ||
            field.type == 'textarea') {
            if (field.value == '') {
                field.value = 0;
            }
            var yvalue = parseFloat(field.value);
            var ivalue = iequal(oEqual[x][2]("equal"), form);
            var itype = oEqual[x][2]("type");
            var re = yvalue - ivalue;
            if (typeof oEqual[x][2]("Difference_maxvalue") == "undefined") {
                var Difference_maxvalue = "0.5";
            } else
            {
                var Difference_maxvalue = oEqual[x][2]("Difference_maxvalue") ;
            }
            if (typeof oEqual[x][2]("Difference_minvalue") == "undefined") {
                var Difference_minvalue = "-0.5";
            } else
            {
                var Difference_minvalue = oEqual[x][2]("Difference_minvalue") ;
            }
            if (parseFloat(Difference_maxvalue) == 0) {
                Difference_maxvalue = "0.5"
            }
            ;
            if (parseFloat(Difference_minvalue) == 0) {
                Difference_minvalue = "-0.5"
            }
            ;
            if ((itype == '=' && (re > parseFloat(Difference_maxvalue) || re < parseFloat(Difference_minvalue))) ||
                (itype == '#1#' && re < parseFloat(Difference_minvalue)) || (itype == '#2#' && re < parseFloat(Difference_minvalue))
                    || (itype == '#3#' && re > parseFloat(Difference_maxvalue)) || (itype == '#4#' && re > parseFloat(Difference_maxvalue))) {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oEqual[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        alert(fields.join('\n'));
    }
    return bValid;
}

function CalculateEqual2_0(form) {
    var formName = form.getAttributeNode("name");
    oEqual = eval('new ' + formName.value + '_equal_0()');
    oEqual_if = eval('new ' + formName.value + '_equal_if()');
    //oEqual = new equal_0();
    //oEqual_if = new equal_if();
    var i = 1;
    var break_bz = true;
    while (true) {
        for (x in oEqual) {
            if (parseInt(oEqual[x][2]("No_Step")) == i) {
                break_bz = false;
                if (oEqual[x][2]("type") == "=") {
                    if (!isNaN(parseFloat(iequal(oEqual[x][2]("equal"), form)))) {
                        var ss = iequal(oEqual[x][2]("equal"), form)  ;
                    }
                    else     var ss = 0;
                    if (parseFloat(oEqual[x][2]("Difference_minvalue")) == 0) {
                        form[oEqual[x][0]].value = formatnumber(ss);
                    } else {
                        if (form[oEqual[x][0]].value == "") {
                            form[oEqual[x][0]].value = 0;
                        }
                        if ((parseFloat(form[oEqual[x][0]].value) - formatnumber(ss)) > parseFloat(oEqual[x][2]("Difference_maxvalue")) || (parseFloat(form[oEqual[x][0]].value) - formatnumber(ss)) < parseFloat(oEqual[x][2]("Difference_minvalue"))) {
                            form[oEqual[x][0]].value = formatnumber(ss);
                        }
                    }
                }
                break;
            }
        }
        if (break_bz == true) {
            for (y in oEqual_if) {
                if (parseInt(oEqual_if[y][2]("No_Step")) == i) {
                    break_bz = false;
                    if (oEqual_if[y][2]("equal_type") == "=") {
                        var ivalue_0 = iequal(oEqual_if[y][2]("if_equal_0"), form);
                        var ivalue_1 = iequal(oEqual_if[y][2]("if_equal_1"), form);
                        if (getresult(ivalue_0, oEqual_if[y][2]("if_type"), ivalue_1)) {
                            var ivalue = iequal(oEqual_if[y][2]("equal_true"), form);
                        } else {
                            var ivalue = iequal(oEqual_if[y][2]("equal_false"), form);
                        }
                        if (!isNaN(ivalue)) {
                            var ss = ivalue  ;
                        }
                        else     var ss = 0;

                        if (parseFloat(oEqual_if[y][2]("Difference_minvalue")) == 0) {
                            form[oEqual_if[y][0]].value = formatnumber(ss);
                        } else {
                            if (form[oEqual_if[y][0]].value == "") {
                                form[oEqual_if[y][0]].value = 0;
                            }
                            if ((parseFloat(form[oEqual_if[y][0]].value) - formatnumber(ss)) > parseFloat(oEqual_if[y][2]("Difference_mayvalue")) || (parseFloat(form[oEqual_if[y][0]].value) - formatnumber(ss)) < parseFloat(oEqual_if[y][2]("Difference_minvalue"))) {
                                form[oEqual_if[y][0]].value = formatnumber(ss);
                            }
                        }
                        break;
                    }
                }
            }
        }
        if (break_bz == true) {
            break;
        }
        break_bz = true;
        i = i + 1;
    }
}

function validateSelected(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oSelected = eval('new ' + formName.value + '_selected()');
    //oSelected = new selected();
    for (x in oSelected) {
        if (form[oSelected[x][0]].value == '') {
            if (i == 0) {
                focusField = form[oSelected[x][0]];
            }
            fields[i++] = oSelected[x][1];
            bValid = false;
        }
        ;
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateSelected_value(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oSelected = eval('new ' + formName.value + '_selected_value()');
    //oSelected = new selected_value();
    for (x in oSelected) {
        if (form[oSelected[x][0]].value == oSelected[x][2]("selected_value")) {
            if (i == 0) {
                focusField = form[oSelected[x][0]];
            }
            fields[i++] = oSelected[x][1];
            bValid = false;
        }
        ;
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateLength(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oLength = eval('new ' + formName.value + '_length()');
    //oLength = new length();
    for (x in oLength) {
        if (form[oLength[x][0]].type == 'text' ||
            form[oLength[x][0]].type == 'textarea') {
            var ilength = parseInt(oLength[x][2]("length"));
            if (form[oLength[x][0]].value.length != 0) {
                if (form[oLength[x][0]].value.length != ilength) {
                    if (i == 0) {
                        focusField = form[oLength[x][0]];
                    }
                    fields[i++] = oLength[x][1];
                    bValid = false;
                }
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateSssq(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oSssqed = eval('new ' + formName.value + '_sssqed()');
    //oSssqed = new sssqed();
    for (x in oSssqed) {
        if (form[oSssqed[x][0]].type == 'text' ||
            form[oSssqed[x][0]].type == 'textarea') {
            if (form[oSssqed[x][0]].value.length > 0) {
                if (form[oSssqed[x][0]].value.substring(4, 5) == '0') {
                    if ((parseInt(form[oSssqed[x][0]].value.substring(0, 4)) < 1990)
                            || (parseInt(form[oSssqed[x][0]].value.substring(0, 4)) > 2010)
                            || (parseInt(form[oSssqed[x][0]].value.substring(5, 6)) < 1)
                            || (parseInt(form[oSssqed[x][0]].value.substring(5, 6)) > 9)) {
                        if (i == 0) {
                            focusField = form[oSssqed[x][0]];
                        }
                        fields[i++] = oSssqed[x][1];
                        bValid = false;
                    }
                } else {
                    if ((parseInt(form[oSssqed[x][0]].value.substring(0, 4)) < 1990)
                            || (parseInt(form[oSssqed[x][0]].value.substring(0, 4)) > 2010)
                            || (parseInt(form[oSssqed[x][0]].value.substring(4, 6)) < 1)
                            || (parseInt(form[oSssqed[x][0]].value.substring(4, 6)) > 12)) {
                        if (i == 0) {
                            focusField = form[oSssqed[x][0]];
                        }
                        fields[i++] = oSssqed[x][1];
                        bValid = false;
                    }
                }
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateValue_length(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oValue_length = eval('new ' + formName.value + '_value_length()');
    //oValue_length = new value_length();
    for (x in oValue_length) {
        if (form[oValue_length[x][2]("dependsname")].value.substring(oValue_length[x][2]("dependsvalue_begin"), oValue_length[x][2]("dependsvalue_end")) == oValue_length[x][2]("dependsvalue")
                && form[oValue_length[x][0]].value.length != oValue_length[x][2]("length")) {
            if (i == 0) {
                focusField = form[oValue_length[x][0]];
            }
            fields[i++] = oValue_length[x][1];
            bValid = false;
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateUnrequired_value(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oUnrequired_value = eval('new ' + formName.value + '_unrequired_value()');
    //oUnrequired_value = new unrequired_value();
    for (x in oUnrequired_value) {
        if (form[oUnrequired_value[x][0]].type == 'text' ||
            form[oUnrequired_value[x][0]].type == 'textarea') {
            if (form[oUnrequired_value[x][0]].value.length > 0) {
                if (i == 0) {
                    focusField = form[oUnrequired_value[x][0]];
                }
                fields[i++] = oUnrequired_value[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateIf_required(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oIf_required = eval('new ' + formName.value + '_if_required()');
    //oIf_required = new if_required();
    for (x in oIf_required) {
        if (form[oIf_required[x][0]].type == 'text' ||
            form[oIf_required[x][0]].type == 'textarea') {

            if (oIf_required[x][2]("if_depends_values").indexOf(form[oIf_required[x][2]("if_depends_name")].value) == -1)
            {
                if (form[oIf_required[x][0]].value.length == 0) {
                    if (i == 0) {
                        focusField = form[oIf_required[x][0]];
                    }
                    fields[i++] = oIf_required[x][1];
                    bValid = false;
                }
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateMust_depends(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oMust_depends = eval('new ' + formName.value + '_must_depends()');
    //oMust_depends = new must_depends();
    for (x in oMust_depends) {
        if (form[oMust_depends[x][0]].value.length == 0) {
            if (imust_depends(oMust_depends[x][2]("must_depends"), form)) {
                if (i == 0) {
                    focusField = form[oMust_depends[x][0]];
                }
                fields[i++] = oMust_depends[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function imust_depends(must_depends, form) {
    split = must_depends.split(',');
    var result = false;
    for (i = 0; i <= split.length - 1; i++) {
        if (parseFloat(form[split[i]].value) != 0 && form[split[i]].value.length > 0) {
            result = true;
            break;
        }
    }
    return result;
}

function validateMust_depends_0(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oMust_depends_0 = eval('new ' + formName.value + '_must_depends_0()');
    //oMust_depends_0 = new must_depends_0();
    for (x in oMust_depends_0) {
        if (form[oMust_depends_0[x][0]].value.length == 0 || parseFloat(form[oMust_depends_0[x][0]].value) == 0) {
            if (imust_depends(oMust_depends_0[x][2]("must_depends"), form)) {
                if (i == 0) {
                    focusField = form[oMust_depends_0[x][0]];
                }
                fields[i++] = oMust_depends_0[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateDis_depends(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oDis_depends = eval('new ' + formName.value + '_dis_depends()');
    //oDis_depends = new dis_depends();
    for (x in oDis_depends) {
        if (form[oDis_depends[x][0]].value.length != 0 && parseFloat(form[oDis_depends[x][0]].value) != 0) {
            if (idis_depends(oDis_depends[x][2]("dis_depends_name"), oDis_depends[x][2]("dis_depends_value"), form)) {
                if (i == 0) {
                    focusField = form[oDis_depends[x][0]];
                }
                fields[i++] = oDis_depends[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function idis_depends(dis_depends_name, dis_depends_value, form) {
    split = dis_depends_value.split(',');
    var result = false;
    for (i = 0; i <= split.length - 1; i++) {
        //alert(form[dis_depends_name].value);
        //alert(split[i]);
        if (form[dis_depends_name].value == split[i]) {
            result = true;
            break;
        }
    }
    return result;
}

function validateDis_depends_0(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oDis_depends_0 = eval('new ' + formName.value + '_dis_depends_0()');
    //oDis_depends_0 = new dis_depends_0();
    for (x in oDis_depends_0) {
        if (form[oDis_depends_0[x][0]].value.length != 0 && parseFloat(form[oDis_depends_0[x][0]].value) != 0) {
            if (idis_depends_0(oDis_depends_0[x][2]("dis_depends_fieldname"), form)) {
                if (i == 0) {
                    focusField = form[oDis_depends_0[x][0]];
                }
                fields[i++] = oDis_depends_0[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function idis_depends_0(dis_depends_fieldname, form) {
    split = dis_depends_fieldname.split(',');
    var result = false;
    for (i = 0; i <= split.length - 1; i++) {
        if (parseFloat(form[split[i]].value) != 0) {
            result = true;
            break;
        }
        ;
    }
    ;
    return result;
}

function validateEqual_if(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oEqual_if = eval('new ' + formName.value + '_equal_if()');
    //oEqual_if = new equal_if();
    for (x in oEqual_if) {
        var field = form[oEqual_if[x][0]];
        if (field.type == 'text' || field.type == 'textarea') {
            var yvalue = parseFloat(field.value);
            var ivalue_0 = iequal(oEqual_if[x][2]("if_equal_0"), form);
            var ivalue_1 = iequal(oEqual_if[x][2]("if_equal_1"), form);
            if (getresult(ivalue_0, oEqual_if[x][2]("if_type"), ivalue_1)) {
                var ivalue = iequal(oEqual_if[x][2]("equal_true"), form);
            } else {
                var ivalue = iequal(oEqual_if[x][2]("equal_false"), form);
            }
            var itype = oEqual_if[x][2]("equal_type");
            var re = yvalue - ivalue;

            if (oEqual_if[x][2]("Difference_maxvalue") == null) {
                var Difference_maxvalue = "0.5";
            } else
            {
                var Difference_maxvalue = oEqual_if[x][2]("Difference_maxvalue") ;
            }
            if (oEqual_if[x][2]("Difference_minvalue") == null) {
                var Difference_minvalue = "-0.5";
            } else
            {
                var Difference_minvalue = oEqual_if[x][2]("Difference_minvalue") ;
            }
            if (parseFloat(Difference_maxvalue) == 0) {
                Difference_maxvalue = "0.5"
            }
            ;
            if (parseFloat(Difference_minvalue) == 0) {
                Difference_minvalue = "-0.5"
            }
            ;
            if ((itype == '=' && (re > parseFloat(Difference_maxvalue) || re < parseFloat(Difference_minvalue))) ||
                (itype == '#1#' && re < parseFloat(Difference_minvalue)) || (itype == '#2#' && re < parseFloat(Difference_minvalue))
                    || (itype == '#3#' && re > parseFloat(Difference_maxvalue)) || (itype == '#4#' && re > parseFloat(Difference_maxvalue))) {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oEqual_if[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }

    return bValid;
}

function CalculateEqual_if2(form) {
    // oEqual_if = new equal_if();
    var formName = form.getAttributeNode("name");
    oEqual_if = eval('new ' + formName.value + '_equal_if()');
    for (x in oEqual_if) {
        if (oEqual_if[x][2]("equal_type") == "=") {
            var ivalue_0 = iequal(oEqual_if[x][2]("if_equal_0"), form);
            var ivalue_1 = iequal(oEqual_if[x][2]("if_equal_1"), form);

            if (getresult(ivalue_0, oEqual_if[x][2]("if_type"), ivalue_1)) {
                var ivalue = iequal(oEqual_if[x][2]("equal_true"), form);
            } else {
                var ivalue = iequal(oEqual_if[x][2]("equal_false"), form);
            }
            if (!isNaN(ivalue)) {
                var ss = ivalue  ;
            }
            else     var ss = 0;

            if (parseFloat(oEqual_if[x][2]("Difference_minvalue")) == 0) {
                form[oEqual_if[x][0]].value = formatnumber(ss);
            } else {
                if (form[oEqual_if[x][0]].value == "") {
                    form[oEqual_if[x][0]].value = 0;
                }

                if ((parseFloat(form[oEqual_if[x][0]].value) - formatnumber(ss)) > parseFloat(oEqual_if[x][2]("Difference_maxvalue")) || (parseFloat(form[oEqual_if[x][0]].value) - formatnumber(ss)) < parseFloat(oEqual_if[x][2]("Difference_minvalue"))) {
                    form[oEqual_if[x][0]].value = formatnumber(ss);
                }
            }
        }
    }
}

function CalculateEqual_if(field, form) {
    var formName = form.getAttributeNode("name");
    oEqual_if = eval('new ' + formName.value + '_equal_if()');
    //oEqual_if = new equal_if();
    for (x in oEqual_if) {
        if (oEqual_if[x][2]("equal_type") == "=") {
            if ((oEqual_if[x][2]("equal_true").indexOf(field.name) != -1  ) || (oEqual_if[x][2]("equal_false").indexOf(field.name) != -1  ) || (field.name == form[oEqual_if[x][0]].name )) {
                var ivalue_0 = iequal(oEqual_if[x][2]("if_equal_0"), form);
                var ivalue_1 = iequal(oEqual_if[x][2]("if_equal_1"), form);

                if (getresult(ivalue_0, oEqual_if[x][2]("if_type"), ivalue_1)) {
                    var ivalue = iequal(oEqual_if[x][2]("equal_true"), form);
                } else {
                    var ivalue = iequal(oEqual_if[x][2]("equal_false"), form);
                }
                if (!isNaN(ivalue)) {
                    var ss = ivalue  ;
                }
                else     var ss = 0;

                if (parseFloat(oEqual_if[x][2]("Difference_minvalue")) == 0) {
                    form[oEqual_if[x][0]].value = formatnumber(ss);
                } else {
                    if (form[oEqual_if[x][0]].value == "") {
                        form[oEqual_if[x][0]].value = 0;
                    }

                    if ((parseFloat(form[oEqual_if[x][0]].value) - formatnumber(ss)) > parseFloat(oEqual_if[x][2]("Difference_maxvalue")) || (parseFloat(form[oEqual_if[x][0]].value) - formatnumber(ss)) < parseFloat(oEqual_if[x][2]("Difference_minvalue"))) {
                        form[oEqual_if[x][0]].value = formatnumber(ss);
                    }
                }

            }

        }
    }
}

function getresult(ivalue_0, if_type, ivalue_1)
{
    var result = false;
    if (if_type == '=') {
        if (ivalue_0 == ivalue_1) {
            result = true
        }
    }
    if (if_type == '#1#') {
        if (ivalue_0 > ivalue_1) {
            result = true
        }
    }
    if (if_type == '#2#') {
        if (ivalue_0 >= ivalue_1) {
            result = true
        }
    }
    if (if_type == '#3#') {
        if (ivalue_0 < ivalue_1) {
            result = true
        }
    }
    if (if_type == '#4#') {
        if (ivalue_0 <= ivalue_1) {
            result = true
        }
    }
    return result;
}

function validateEqual_if_0(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oEqual_if_0 = eval('new ' + formName.value + '_equal_if_0()');
    //oEqual_if_0 = new equal_if_0();
    for (x in oEqual_if_0) {
        var field = form[oEqual_if_0[x][0]];
        if (field.type == 'text' || field.type == 'textarea') {
            var yvalue = parseFloat(field.value);
            var ivalue_0 = iequal(oEqual_if_0[x][2]("if_equal_0"), form);
            var ivalue_1 = iequal(oEqual_if_0[x][2]("if_equal_1"), form);
            if (getresult(ivalue_0, oEqual_if_0[x][2]("if_type"), ivalue_1)) {
                var ivalue = iequal(oEqual_if_0[x][2]("equal_true"), form);
            } else {
                var ivalue = iequal(oEqual_if_0[x][2]("equal_false"), form);
            }
            var itype = oEqual_if_0[x][2]("equal_type");
            var re = yvalue - ivalue;

            if (oEqual_if_0[x][2]("Difference_maxvalue") == null) {
                var Difference_maxvalue = "0.5";
            } else
            {
                var Difference_maxvalue = oEqual_if_0[x][2]("Difference_maxvalue") ;
            }
            if (oEqual_if_0[x][2]("Difference_minvalue") == null) {
                var Difference_minvalue = "-0.5";
            } else
            {
                var Difference_minvalue = oEqual_if_0[x][2]("Difference_minvalue") ;
            }
            if (parseFloat(Difference_maxvalue) == 0) {
                Difference_maxvalue = "0.5"
            }
            ;
            if (parseFloat(Difference_minvalue) == 0) {
                Difference_minvalue = "-0.5"
            }
            ;
            if ((itype == '=' && (re > parseFloat(Difference_maxvalue) || re < parseFloat(Difference_minvalue))) ||
                (itype == '#1#' && re < parseFloat(Difference_minvalue)) || (itype == '#2#' && re < parseFloat(Difference_minvalue))
                    || (itype == '#3#' && re > parseFloat(Difference_maxvalue)) || (itype == '#4#' && re > parseFloat(Difference_maxvalue))) {
                if (i == 0) {
                    focusField = field;
                }
                fields[i++] = oEqual_if_0[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        alert(fields.join('\n'));
    }

    return bValid;
}

function validateEqual_case(form) {
    var bValid = true;
    var breakbz = false;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oEqual_case = eval('new ' + formName.value + '_equal_case()');
    //oEqual_case = new equal_case();
    for (x in oEqual_case) {
        var field = form[oEqual_case[x][0]];
        if (field.type == 'text' || field.type == 'textarea') {
            var yvalue = parseFloat(field.value);
            for (m = 1; m <= parseInt(oEqual_case[x][2]("equal_num")); m++) {
                if (getresult(form[oEqual_case[x][2]("case_name_" + m)].value, oEqual_case[x][2]("case_type_" + m), oEqual_case[x][2]("case_value_" + m)))
                {
                    var ivalue = iequal(oEqual_case[x][2](oEqual_case[x][2]("case_equal_" + m + "_name")), form);
                    var itype = oEqual_case[x][2]("equal_" + m + "_type");
                    var re = yvalue - ivalue;
                    if (oEqual_case[x][2]("Difference_maxvalue") == null) {
                        var Difference_maxvalue = "0.5";
                    } else
                    {
                        var Difference_maxvalue = oEqual_case[x][2]("Difference_maxvalue") ;
                    }
                    if (oEqual_case[x][2]("Difference_minvalue") == null) {
                        var Difference_minvalue = "-0.5";
                    } else
                    {
                        var Difference_minvalue = oEqual_case[x][2]("Difference_minvalue") ;
                    }
                    if (parseFloat(Difference_maxvalue) == 0) {
                        Difference_maxvalue = "0.5"
                    }
                    ;
                    if (parseFloat(Difference_minvalue) == 0) {
                        Difference_minvalue = "-0.5"
                    }
                    ;
                    if ((itype == '=' && (re > parseFloat(Difference_maxvalue) || re < parseFloat(Difference_minvalue))) ||
                        (itype == '#1#' && re < parseFloat(Difference_minvalue)) || (itype == '#2#' && re < parseFloat(Difference_minvalue))
                            || (itype == '#3#' && re > parseFloat(Difference_maxvalue)) || (itype == '#4#' && re > parseFloat(Difference_maxvalue))) {
                        if (i == 0) {
                            focusField = field;
                        }
                        fields[i++] = oEqual_case[x][1];
                        bValid = false;
                    }
                    breakbz = true;
                }
                if (breakbz == true) {
                    break;
                }
            }
            breakbz = false;
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}


function CalculateEqual_case(field, form) {
    var formName = form.getAttributeNode("name");
    oEqual_case = eval('new ' + formName.value + '_equal_case()');
    // oEqual_case = new equal_case();
    for (x in oEqual_case) {
        for (m = 1; m <= parseInt(oEqual_case[x][2]("equal_num")); m++) {
            //alert(oEqual_case[x][2]("equal_" + m + "_type"));
            if (oEqual_case[x][2]("equal_" + m + "_type") == "=") {
                if ((oEqual_case[x][2](oEqual_case[x][2]("case_equal_" + m + "_name")).indexOf(field.name) != -1  ) || (field.name == form[oEqual_case[x][0]].name )) {
                    if (getresult(form[oEqual_case[x][2]("case_name_" + m)].value, oEqual_case[x][2]("case_type_" + m), oEqual_case[x][2]("case_value_" + m)))
                    {
                        if (!isNaN(parseFloat(iequal(oEqual_case[x][2](oEqual_case[x][2]("case_equal_" + m + "_name")), form)))) {
                            var ss = iequal(oEqual_case[x][2](oEqual_case[x][2]("case_equal_" + m + "_name")), form);
                        }
                        else     var ss = 0;
                        //alert(ss);
                        if (parseFloat(oEqual_case[x][2]("Difference_minvalue")) == 0) {
                            form[oEqual_case[x][0]].value = formatnumber(ss);
                        } else {
                            if (form[oEqual_case[x][0]].value == "") {
                                form[oEqual_case[x][0]].value = 0;
                            }
                            if ((parseFloat(form[oEqual_case[x][0]].value) - formatnumber(ss)) > parseFloat(oEqual_case[x][2]("Difference_maxvalue")) || (parseFloat(form[oEqual_case[x][0]].value) - formatnumber(ss)) < parseFloat(oEqual_case[x][2]("Difference_minvalue"))) {
                                form[oEqual_case[x][0]].value = formatnumber(ss);
                            }
                        }
                    }
                }
            }
        }
    }
}

function validateEqual_case_0(form) {
    var bValid = true;
    var breakbz = false;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oEqual_case = eval('new ' + formName.value + '_equal_case_0()');
    //oEqual_case = new equal_case_0();
    for (x in oEqual_case) {
        var field = form[oEqual_case[x][0]];
        if (field.type == 'text' || field.type == 'textarea') {
            var yvalue = parseFloat(field.value);
            for (m = 1; m <= parseInt(oEqual_case[x][2]("equal_num")); m++) {
                if (getresult(form[oEqual_case[x][2]("case_name_" + m)].value, oEqual_case[x][2]("case_type_" + m), oEqual_case[x][2]("case_value_" + m)))
                {
                    var ivalue = iequal(oEqual_case[x][2](oEqual_case[x][2]("case_equal_" + m + "_name")), form);
                    var itype = oEqual_case[x][2]("equal_" + m + "_type");
                    var re = yvalue - ivalue;
                    if (oEqual_case[x][2]("Difference_maxvalue") == null) {
                        var Difference_maxvalue = "0.5";
                    } else
                    {
                        var Difference_maxvalue = oEqual_case[x][2]("Difference_maxvalue") ;
                    }
                    if (oEqual_case[x][2]("Difference_minvalue") == null) {
                        var Difference_minvalue = "-0.5";
                    } else
                    {
                        var Difference_minvalue = oEqual_case[x][2]("Difference_minvalue") ;
                    }
                    if (parseFloat(Difference_maxvalue) == 0) {
                        Difference_maxvalue = "0.5"
                    }
                    ;
                    if (parseFloat(Difference_minvalue) == 0) {
                        Difference_minvalue = "-0.5"
                    }
                    ;
                    if ((itype == '=' && (re > parseFloat(Difference_maxvalue) || re < parseFloat(Difference_minvalue))) ||
                        (itype == '#1#' && re < parseFloat(Difference_minvalue)) || (itype == '#2#' && re < parseFloat(Difference_minvalue))
                            || (itype == '#3#' && re > parseFloat(Difference_maxvalue)) || (itype == '#4#' && re > parseFloat(Difference_maxvalue))) {
                        if (i == 0) {
                            focusField = field;
                        }
                        fields[i++] = oEqual_case[x][1];
                        bValid = false;
                    }
                    breakbz = true;
                }
                if (breakbz == true) {
                    break;
                }
            }
            breakbz = false;
        }
    }
    if (fields.length > 0) {
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateEqual_case_and(form) {
    var bValid = true;
    var breakbz = false;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oEqual_case_and = eval('new ' + formName.value + '_equal_case_and()');
    //oEqual_case_and = new equal_case_and();
    for (x in oEqual_case_and) {
        var field = form[oEqual_case_and[x][0]];
        if (field.type == 'text' || field.type == 'textarea') {
            var yvalue = parseFloat(field.value);
            for (m = 1; m <= parseInt(oEqual_case_and[x][2]("equal_num")); m++) {
                if (getresult_0(oEqual_case_and[x][2]("case_value_" + m), form))
                {
                    var ivalue = iequal(oEqual_case_and[x][2](oEqual_case_and[x][2]("case_equal_" + m + "_true")), form);
                    var itype = oEqual_case_and[x][2]("equal_" + m + "_type");
                    var re = yvalue - ivalue;
                    if (oEqual_case_and[x][2]("Difference_maxvalue") == null) {
                        var Difference_maxvalue = "0.5";
                    } else
                    {
                        var Difference_maxvalue = oEqual_case_and[x][2]("Difference_maxvalue") ;
                    }
                    if (oEqual_case_and[x][2]("Difference_minvalue") == null) {
                        var Difference_minvalue = "-0.5";
                    } else
                    {
                        var Difference_minvalue = oEqual_case_and[x][2]("Difference_minvalue") ;
                    }
                    if (parseFloat(Difference_maxvalue) == 0) {
                        Difference_maxvalue = "0.5"
                    }
                    ;
                    if (parseFloat(Difference_minvalue) == 0) {
                        Difference_minvalue = "-0.5"
                    }
                    ;
                    if ((itype == '=' && (re > parseFloat(Difference_maxvalue) || re < parseFloat(Difference_minvalue))) ||
                        (itype == '#1#' && re < parseFloat(Difference_minvalue)) || (itype == '#2#' && re < parseFloat(Difference_minvalue))
                            || (itype == '#3#' && re > parseFloat(Difference_maxvalue)) || (itype == '#4#' && re > parseFloat(Difference_maxvalue))) {
                        if (i == 0) {
                            focusField = field;
                        }
                        fields[i++] = oEqual_case_and[x][1];
                        bValid = false;
                    }
                    breakbz = true;
                }
                if (breakbz == true) {
                    break;
                }
            }
            breakbz = false;
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function getresult_0(string_value, form)
{
    var result = false;
    split_getresult0 = string_value.split('@$');
    var valueArray0 = new Array()
    var tt = 0;
    for (ss = 0; ss <= split_getresult0.length; ss++) {
        split_getresult1 = split_getresult0[ss].split('@%');
        left_equal = iequal(split_getresult1[0], form);
        equal_type = split_getresult1[1];
        right_equal = iequal(split_getresult1[2], form);
        valueArray0[tt] = getresult(left_equal, equal_type, right_equal);
        if (ss + 1 < split_getresult0.length) {
            valueArray0[tt + 1] = split_getresult0[ss + 1];
        }
        ss = ss + 1;
        tt = tt + 2;
    }
    var s = 0;
    for (v = 0; v < valueArray0.length; v++) {
        if (valueArray0[v] == "^^") {
            s = s + 1
        }
    }
    var result = false;
    var vv = 0;
    var v = 0;
    while (v < s) {
        var valueArray_temp = new Array();
        for (t = 0; t <= valueArray0.length; t++) {
            if (valueArray0[t + 1] == '^^') {
                if (valueArray0[t] && valueArray0[t + 2]) {
                    valueArray_temp[vv] = true;
                }
                else {
                    valueArray_temp[vv] = false;
                }
                vv = vv + 1;
                for (o = t + 3; o < valueArray0.length; o++) {
                    valueArray_temp[vv] = valueArray0[o];
                    vv = vv + 1;
                }
                v = v + 1;
                t = o;
            } else {
                valueArray_temp[vv] = valueArray0[t];
            }
            vv = vv + 1;
        }
        valueArray0 = valueArray_temp;
    }
    for (o = 0; o < valueArray0.length; o++) {
        if (valueArray0[o] == true) {
            result = true
        }
    }
    return  result;
}


function CalculateEqual_case_and(field, form) {
    var formName = form.getAttributeNode("name");
    oEqual_case_and = eval('new ' + formName.value + '_equal_case_and()');
    //oEqual_case_and = new equal_case_and();
    for (x in oEqual_case_and) {
        for (m = 1; m <= parseInt(oEqual_case_and[x][2]("equal_num")); m++) {
            if (oEqual_case_and[x][2]("equal_" + m + "_type") == "=") {
                if ((oEqual_case_and[x][2](oEqual_case_and[x][2]("case_equal_" + m + "_true")).indexOf(field.name) != -1  ) || (field.name == form[oEqual_case_and[x][0]].name )) {
                    if (getresult_0(oEqual_case_and[x][2]("case_value_" + m), form))
                    {
                        if (!isNaN(parseFloat(iequal(oEqual_case_and[x][2](oEqual_case_and[x][2]("case_equal_" + m + "_true")), form)))) {
                            var ss = iequal(oEqual_case_and[x][2](oEqual_case_and[x][2]("case_equal_" + m + "_true")), form);
                        }
                        else     var ss = 0;

                        if (parseFloat(oEqual_case_and[x][2]("Difference_minvalue")) == 0) {
                            form[oEqual_case_and[x][0]].value = formatnumber(ss);
                        } else {
                            if (form[oEqual_case_and[x][0]].value == "") {
                                form[oEqual_case_and[x][0]].value = 0;
                            }
                            if ((parseFloat(form[oEqual_case_and[x][0]].value) - formatnumber(ss)) > parseFloat(oEqual_case_and[x][2]("Difference_maxvalue")) || (parseFloat(form[oEqual_case_and[x][0]].value) - formatnumber(ss)) < parseFloat(oEqual_case_and[x][2]("Difference_minvalue"))) {
                                form[oEqual_case_and[x][0]].value = formatnumber(ss);
                            }
                        }
                    }
                }
            }
        }
    }
}

function validateMinLength_0(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oMinLength_0 = eval('new ' + formName.value + '_minlength_0()');
    //oMinLength_0 = new minlength_0();
    for (x in oMinLength_0) {
        if (form[oMinLength_0[x][0]].type == 'text' ||
            form[oMinLength_0[x][0]].type == 'textarea') {
            var iMin = parseInt(oMinLength_0[x][2]("minlength"));
            if (form[oMinLength_0[x][0]].value.length < iMin && form[oMinLength_0[x][0]].value.length > 0) {
                if (i == 0) {
                    focusField = form[oMinLength_0[x][0]];
                }
                fields[i++] = oMinLength_0[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateMust_in_values(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oMust_in_values = eval('new ' + formName.value + '_must_in_values()');
    // oMust_in_values = new must_in_values();
    for (x in oMust_in_values) {
        if (form[oMust_in_values[x][0]].type == 'text' ||
            form[oMust_in_values[x][0]].type == 'textarea') {
            if (imust_value(form[oMust_in_values[x][0]].value, oMust_in_values[x][2]("must_in_values")))
            {
                if (form[oMust_in_values[x][0]].value != 0) {
                    if (i == 0) {
                        focusField = form[oMust_in_values[x][0]];
                    }
                    fields[i++] = oMust_in_values[x][1];
                    bValid = false;
                }
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function imust_value(must_value, must_depends) {
    split = must_depends.split(',');
    var result = true;
    for (i = 0; i <= split.length - 1; i++) {
        if (parseFloat(split[i]) == parseFloat(must_value)) {
            result = false;
            break;
        }
        ;
    }
    ;
    return result;
}

function validateMust_in_values_0(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oMust_in_values_0 = eval('new ' + formName.value + '_must_in_values_0()');
    //oMust_in_values_0 = new must_in_values_0();
    for (x in oMust_in_values_0) {
        if (form[oMust_in_values_0[x][0]].type == 'text' ||
            form[oMust_in_values_0[x][0]].type == 'textarea') {
            if (imust_value(form[oMust_in_values_0[x][0]].value, oMust_in_values_0[x][2]("must_in_values")))
            {
                if (i == 0) {
                    focusField = form[oMust_in_values_0[x][0]];
                }
                fields[i++] = oMust_in_values_0[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateValue_must_in_values(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oValue_must_in_values = eval('new ' + formName.value + '_value_must_in_values()');
    //oValue_must_in_values = new value_must_in_values();
    for (x in oValue_must_in_values) {
        if (form[oValue_must_in_values[x][0]].type == 'text' ||
            form[oValue_must_in_values[x][0]].type == 'textarea') {
            if (form[oValue_must_in_values[x][2]("dependsname")].value.substring(oValue_must_in_values[x][2]("dependsvalue_begin"), oValue_must_in_values[x][2]("dependsvalue_end")) == oValue_must_in_values[x][2]("dependsvalue")) {
                if (ivalue_must_value(form[oValue_must_in_values[x][0]].value, oValue_must_in_values[x][2]("value_must_in_values")))
                {
                    if (form[oValue_must_in_values[x][0]].value != 0) {
                        if (i == 0) {
                            focusField = form[oValue_must_in_values[x][0]];
                        }
                        fields[i++] = oValue_must_in_values[x][1];
                        bValid = false;
                    }
                }
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function ivalue_must_value(must_value, must_depends) {
    split = must_depends.split(',');
    var result = true;
    for (i = 0; i <= split.length - 1; i++) {
        if (parseFloat(split[i]) == parseFloat(must_value)) {
            result = false;
            break;
        }
        ;
    }
    ;
    return result;
}

function validateStringvalue_equal(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oStringvalue_equal = eval('new ' + formName.value + '_stringvalue_equal()');
    //oStringvalue_equal = new stringvalue_equal();
    for (x in oStringvalue_equal) {
        if (form[oStringvalue_equal[x][0]].value.substring(oStringvalue_equal[x][2]("value_begin"), oStringvalue_equal[x][2]("value_end")) !=
            form[oStringvalue_equal[x][2]("dependsname")].value.substring(oStringvalue_equal[x][2]("dependsvalue_begin"), oStringvalue_equal[x][2]("dependsvalue_end"))
                && form[oStringvalue_equal[x][2]("dependsname")].value.length != 0 && form[oStringvalue_equal[x][0]].value.length != 0) {
            if (i == 0) {
                focusField = form[oStringvalue_equal[x][0]];
            }
            fields[i++] = oStringvalue_equal[x][1];
            bValid = false;
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}

function validateIntRange_year_tax(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    var formName = form.getAttributeNode("name");
    oRange = eval('new ' + formName.value + '_intRange_year_tax()');
    //oRange = new intRange_year_tax();
    for (x in oRange) {
        if ((form[oRange[x][0]].type == 'text' ||
             form[oRange[x][0]].type == 'textarea') &&
            (form[oRange[x][0]].value.length > 0) && (form[oRange[x][0]].value != '0')) {
            var iMin = parseInt(oRange[x][2]("min"));
            var iMax = parseInt(oRange[x][2]("max"));
            var iValue = parseInt(form[oRange[x][0]].value);
            if (!(iValue >= iMin && iValue <= iMax)) {
                if (i == 0) {
                    focusField = form[oRange[x][0]];
                }
                fields[i++] = oRange[x][1];
                bValid = false;
            }
        }
    }
    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }
    return bValid;
}
